package mysql

import (
	"gorm.io/gorm"
)

type User struct {
	gorm.Model
	Phone    string `gorm:"type:char(11);not null;comment:'手机号'"`
	Password string `gorm:"type:char(32);not null;comment:'密码'"`
	Status   int    `gorm:"type:int;not null;comment:状态:1-正常,2-冻结"`
}

func (u *User) GetUser(Page, PageSize, Status int) (user []User, err2 error) {
	if Status == 0 {
		DB.Offset((Page - 1) * PageSize).Limit(PageSize).Find(&user)
	} else {
		DB.Where("status = ?", Status).Offset((Page - 1) * PageSize).Limit(PageSize).Find(&user)
	}
	return
}

func (u *User) UpdateStatus(id, Status int) error {
	return DB.Model(&u).Where("id = ?", id).Update("status", Status).Error
}
